<?php
class Bahan_baku extends CI_Model {
	function __construct() {
		parent::__construct();
	}
	
	function get($where = NULL){
		if($where != NULL){
			$this->db->where($where);
		}
		$this->db->from('bahan_baku');
		return $this->db->get();
	}
	
	function add($data){
		$this->db->insert('bahan_baku',$data);
		return $this->db->insert_id();
	}
	
	function edit($id,$data){
		$this->db->where('id_bahan_baku',$id);
		return $this->db->update('bahan_baku',$data);
	}
	
	function delete($id){
		$this->db->where('id_bahan_baku',$id);
		return $this->db->delete('bahan_baku');
	}
	
	//transaksi gudang
	function get_gudang(){
		$this->db->select('*');
		$this->db->from('transaksi_gudang as tg');
		$this->db->join('bahan_baku as bb', 'bb.id_bahan_baku = tg.id_bahan_baku');
		$this->db->where('tg.tgl_expired BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 7 DAY)');
		return $this->db->get()->result_array();
	}
	
	function add_gudang($data){
		$this->db->insert('transaksi_gudang',$data);
		return $this->db->insert_id();
	}
	
}